package com.jielihaofeng.nio.bytebuffer;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

import static com.jielihaofeng.nio.bytebuffer.ByteBufferUtil.debugAll;

/**
 * @description 测试 scatter 读 [集中读取]
 * @author Johnnie Wind
 * @date 2021/10/1 20:47
 */
public class TestScatteringReads {

    public static void main(String[] args) {

        try(FileChannel channel = new RandomAccessFile("words.txt","r").getChannel()){
            ByteBuffer b1 = ByteBuffer.allocateDirect(3);
            ByteBuffer b2 = ByteBuffer.allocateDirect(3);
            ByteBuffer b3 = ByteBuffer.allocateDirect(5);
            channel.read(new ByteBuffer[]{b1,b2,b3});
            b1.flip();
            b2.flip();
            b3.flip();
            debugAll(b1);
            debugAll(b2);
            debugAll(b3);
        }catch (IOException e){

        }

    }

}
